#include "StdAfx.h"
#include "Actor.h"
#include "Graphics\Model.h"

Actor::Actor(float fMass, Geometries* geometry, PhysicsGeometry* physics):PhysicalObject(physics, fMass)
{
	m_Model = new Model(geometry);
	m_vTargetPos = GetPosition();
	m_mass = fMass;
	m_speed = 2.0f;
}


Actor::~Actor(void)
{
	delete m_Model;
}


void Actor::Draw()
{
	m_Model->Draw();
}

bool Actor::Update(float fDeltaTime)
{
	//Update the position of the actor
	const Vector4 vPos = GetPosition();
	Vector4 vDirection = m_vTargetPos - vPos;
	float distSquared = vDirection.LengthSquared();

	//if we are within a cm then we are close enough, otherwise move closer if possible
	if( distSquared > 0.01f )
	{
		vDirection.Normalize();
		Vector4 vForce = vDirection * m_speed;
		ApplyForce(fDeltaTime, vForce);

		SetPosition(vPos + (vForce * fDeltaTime));
	}

	return true;
}